/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.manager.create;

import br.com.foxline.model.*;
import br.com.foxline.service.*;
import java.io.Serializable;
import java.util.*;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.*;
import org.primefaces.model.DualListModel;

/**
 *
 * @author ely
 */
@ManagedBean
@ViewScoped
public class ManagerCreateUser implements Serializable{

    @EJB
    UserService userService;
    @EJB
    GroupService groupService;
    
    private Users user;
    private String confirm;
    
    private DualListModel<Groups> dualGrupo;
    private List<Groups> gruposSelec;
    
    @PostConstruct
    public void init() {
        user = new Users();
        gruposSelec = new ArrayList<Groups>();
        dualGrupo = new DualListModel<Groups>(groupService.findAll(), gruposSelec);
    }

    public void save() {
        user.setGroups(dualGrupo.getTarget());
        userService.saveUser(confirm, user);
        init();
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public String getConfirm() {
        return confirm;
    }

    public void setConfirm(String confirm) {
        this.confirm = confirm;
    }

    public DualListModel<Groups> getDualGrupo() {
         dualGrupo = new DualListModel<Groups>(groupService.findAll(), gruposSelec);
        return dualGrupo;
    }

    public void setDualGrupo(DualListModel<Groups> dualGrupo) {
        this.dualGrupo = dualGrupo;
    }

  
}
